package com.scorpio.auth.controller;

import com.scorpio.auth.enums.UserEnum;
import com.scorpio.tools.api.R;
import com.scorpio.tools.utils.Func;
import com.scorpio.tools.utils.JwtUtil;
import com.scorpio.tools.utils.WebUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author sdaduanbilei
 */
@Api(value = "用户授权认证", tags = "授权接口")
@RestController
public class AuthController {

    @Value("${jwt.secret}")
    private String secret;

    @Value("${jwt.expire}")
    private long expire;


    @PostMapping("token")
    public R token(@RequestParam String account,@RequestParam String pwd) {
        String userType = Func.toStr(WebUtil.getRequest().getHeader("user-type"), UserEnum.WEB.getName());
        String token = JwtUtil.sign(account,secret,userType,expire);
        return R.data(token);
    }
}
